package com.hzspace.customaopannotation.aspect;

import com.hzspace.customaopannotation.annotation.Log;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

/**
 * @Author: LiuHao
 * @Descirption:
 * @Date: 2020/2/22_18:01
 */
@Slf4j
@Component
@Aspect
public class LogAspect {

    @Pointcut("@annotation(com.hzspace.customaopannotation.annotation.Log)")
    public void pointCut(){}


    @Around("pointCut()")
    public void doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Log LOG = ((MethodSignature)proceedingJoinPoint.getSignature()).getMethod().getAnnotation(Log.class);
        if(LOG != null && LOG.writeLog()){
            log.info(((MethodSignature)proceedingJoinPoint.getSignature()).getMethod().getName()+"打印日志......");
        }
        proceedingJoinPoint.proceed();
    }
}
